//
// Created by mac on 1/28/22.
//
#include <iostream>

using namespace std;
int divide(int dividend, int divisor) {
    if (dividend == INT_MIN && divisor == -1) return INT_MAX;
    int sign = (dividend > 0) ^ (divisor > 0) ? -1 : 1;
    unsigned int ua = abs(dividend);
    unsigned int ub = abs(divisor);
    unsigned int res = 0;
    for (int i = 31; i >= 0; i--) {
        if ((ua >> i) >= ub) {
            ua = ua - (ub << i);
            res += 1 << i;
        }
    }

    return sign == 1 ? res : -res;

}
